package com.itheima.appserver.controller;

import com.itheima.appserver.exception.BusinessException;
import com.itheima.appserver.service.UserService;
import com.itheima.model.vo.ErrorResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginContrller {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
        //获取用户手机
        String phone = (String) map.get("phone");
        //发送验证码
        userService.sendMsg(phone);
        return ResponseEntity.ok("发送成功");
    }

    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
        //获取用户手机以及用户输入的验证码
        String phone = (String) map.get("phone");
        String verificationCode = (String) map.get("verificationCode");
        //调用userservice登录
        Map retmap = userService.loginVerification(phone, verificationCode);
        return ResponseEntity.ok(retmap);
    }
}
